package com.zch.string_;

public class String01 {
    public static void main(String[] args) {
        String a = "Hello";
        String b = "World";
        String c = a + b;
        String d = "HelloWorld";
        System.out.println(c == d); //false
        /*
            底层是StringBuilder sb = new StringBuilder();sb.append(a);sb.append(b);
            sb是在堆中，并且append是在原来字符串的基础上追加的
         */
        String e = "Hello" + "World"; //编译器优化为String e = "HelloWorld"
        System.out.println(d == e); //true
        /*
            重要规则：
            1.String c1 = "ab" + "cd";常量相加看的是池
            2.String c1 = a + b;变量相加看的是堆
         */

    }
}
